import java.util.*;

public class DoubleColorBall {
    public static void main(String[] args) {
        // 生成中奖号码
        Set<Integer> winningRedBalls = generateRedBalls();
        int winningBlueBall = generateBlueBall();

        // 显示中奖号码
        System.out.println("本期中奖号码：红球 " + winningRedBalls + " 蓝球 [" + winningBlueBall + "]");

        // 用户输入投注号码
        Set<Integer> userRedBalls = new HashSet<>();
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你的 6 个红球号码（1-33，不能重复）：");
        while (userRedBalls.size() < 6) {
            int num = scanner.nextInt();
            if (num < 1 || num > 33 || userRedBalls.contains(num)) {
                System.out.println("输入错误，请重新输入！");
            } else {
                userRedBalls.add(num);
            }
        }

        System.out.println("请输入你的 1 个蓝球号码（1-16）：");
        int userBlueBall;
        while (true) {
            userBlueBall = scanner.nextInt();
            if (userBlueBall < 1 || userBlueBall > 16) {
                System.out.println("输入错误，请重新输入！");
            } else {
                break;
            }
        }
        scanner.close();

        // 计算匹配情况
        int redMatchCount = 0;
        for (int num : userRedBalls) {
            if (winningRedBalls.contains(num)) {
                redMatchCount++;
            }
        }
        boolean blueMatch = (userBlueBall == winningBlueBall);

        // 计算中奖等级
        String prizeLevel = determinePrize(redMatchCount, blueMatch);
        System.out.println("匹配红球数量：" + redMatchCount + "，匹配蓝球：" + (blueMatch ? "是" : "否"));
        System.out.println("中奖等级：" + prizeLevel);
    }

    // 生成 6 个不重复的红球
    private static Set<Integer> generateRedBalls() {
        Set<Integer> redBalls = new HashSet<>();
        Random rand = new Random();
        while (redBalls.size() < 6) {
            redBalls.add(rand.nextInt(33) + 1);
        }
        return redBalls;
    }

    // 生成 1 个蓝球
    private static int generateBlueBall() {
        Random rand = new Random();
        return rand.nextInt(16) + 1;
    }

    // 判断中奖等级
    private static String determinePrize(int redCount, boolean blueMatch) {
        if (redCount == 6 && blueMatch) return "一等奖（1000万）";
        if (redCount == 6) return "二等奖（50万）";
        if (redCount == 5 && blueMatch) return "三等奖（3000元）";
        if (redCount == 5 || (redCount == 4 && blueMatch)) return "四等奖（200元）";
        if (redCount == 4 || (redCount == 3 && blueMatch)) return "五等奖（10元）";
        if (blueMatch) return "六等奖（5元）";
        return "未中奖";
    }
}
